package Flink.transformation;

import Flink.bean.WaterSensor;
import Flink.function.UserFilter;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class UDFTrans {
    // Todo 用户自定义函数（UDF）
    // Flink暴露了所有UDF函数的接口，具体实现方式为接口或者抽象类，例如MapFunction、
    // FilterFunction、ReduceFunction等。所以用户可以自定义一个函数类，实现对应的接口。
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStreamSource<WaterSensor> stream = env.fromElements(

                new WaterSensor("sensor_1", 1L, 1),
                new WaterSensor("sensor_1", 2L, 2),
                new WaterSensor("sensor_2", 2L, 2),
                new WaterSensor("sensor_3", 3L, 3)
        );
        // lambda表达式
        stream.filter(data -> "sensor_1".equals(data.getId())).print();

        env.execute();
    }
}
